<template>
  <CompOperate v-if="getReportStepInfo" :field="field" :designer="designer" :design-state="designState"
    :parent-list="parentList" :parent-widget="parentWidget" :sub-form-row-id="subFormRowId"
    :sub-form-row-index="subFormRowIndex" :sub-form-col-index="subFormColIndex"
    :index-of-parent-list="indexOfParentList" :display-style="field.options.displayStyle">
    <div class="scene-call-widget" :style="getStyle('wrap')">
      <div class="box" :class="'view-mode-'+optionsInfo.viewMode">
        <div class="left" v-if="optionsInfo.isIcon">
          <Icon name="volume" :style="getStyle('head')" />
        </div>
        <div class="right" :key="uuid">

          <div :style="getStyle('list')">
            <!-- <template v-if="!!getCallPatientInfo && !!(getCallPatientInfo.length)"> -->
            <!-- <vue-seamless-scroll ref="scroll" class="scroll" @ScrollEnd="handleEnd" :data="getCallPatientInfo"> -->
            <div v-for="item in getCallPatientInfo" class="notice">
              <span>请</span>
              <span class="patient center-font" :style="getStyle('patient')">{{ item.orderNo || '\u00a0'
                }}&nbsp;{{
    item.patientName || '\u00a0' }}</span>
              <span>到</span>
              <span class="dept center-font" :style="getStyle('dept')">{{ item.deptName || '\u00a0' }}&nbsp;{{
    item.treatmentRoomName || '\u00a0' }}</span>
              <span>就诊</span>
            </div>

            <!-- </vue-seamless-scroll> -->

            <!-- </template> -->


          </div>

        </div>
      </div>
    </div>
  </CompOperate>
</template>

<script>
import { Icon, NoticeBar } from 'vant';
import { v4 as uuid } from 'uuid';
import { pxToVw, remToPx } from '@/utils/common'
import emitter from "@/utils/designer/emitter";
import CompOperate from "@c/public/form-designer/devType/modules/compOperate.vue";
import mixin from "@sc/templateDetails/modules/homeMiddle/fieldMixin";
import vueSeamlessScroll from 'vue-seamless-scroll';
import {buildParentApi} from "@/utils/designer/util";

export default {
  name: "scene-call-widget",

  componentName: "FieldWidget", //必须固定为FieldWidget，用于接收父级组件的broadcast事件

  mixins: [emitter, mixin],

  props: {
    field: Object,
    parentWidget: Object,
    parentList: Array,
    indexOfParentList: Number,
    selectedWidget: Object,
    designer: Object,
    devType: {
      type: Boolean,
      default: false,
    },
    designState: {
      type: Boolean,
      default: false,
    },
    subFormRowIndex: {
      /* 子表单组件行索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormColIndex: {
      /* 子表单组件列索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormRowId: {
      /* 子表单组件行Id，唯一id且不可变 */ type: String,
      default: "",
    },
    noticeContent: {
      type: String,
      default: '',
    },
    enableScroll: {
      type: Boolean,
      default: false,
    },
  },

  components: {
    Icon,
    NoticeBar,
    CompOperate,
    vueSeamlessScroll
  },

  data() {
    return {
      list: [],
      uuid: uuid(),
      optionsInfo: Object(),
    }
  },

  computed: {
    // 获取报到机的步距
    getReportStepInfo() {
      let info = this.$store.getters['getReportStepInfo'];
      return info !== 1
    },

    // 温馨提示的滚动
    classOptionTips() {
      let { scrollableNumber } = (this.optionsInfo.speed)
      return {
        step: [1, 1.5, 2, 2.5, 3][0], // 数值越大速度滚动越快
        hoverStop: true,
        limitMoveNum: scrollableNumber, // 开始无缝滚动的数据量 this.dataList.length
        direction: 2 // 0向下 1向上 2向左 3向右
      };
    },

    getCallPatientInfo() {
      // 获取 getCallPatientInfo
      let devType = (this.devType);
      let info = this.$store.getters['getCallPatientInfo'];
      if (devType) {
        const arr = info.apiData.treatingPatientList || [];
        return arr.length ? arr : [{}];
      } else {
        return info.mockData || [];
      }
    },


    // 获取设置的行内样式
    getStyle() {
      return function (val) {
        const self = this;
        let info = (self.optionsInfo) || Object();
        let Obj = Object();
        switch (val) {
          case 'wrap':
            if (!!info.backgroundColor) {
              Reflect.set(Obj, 'backgroundColor', `${(info.backgroundColor)}`);
            } else {
              Reflect.deleteProperty(Obj, 'backgroundColor');
            }
            Reflect.set(Obj, 'height', pxToVw(info.contentHeight));
            Reflect.set(Obj, 'justify-content', info.isCenter ? 'center' : 'flex-start');
            return Obj;
          case 'head':
            Reflect.set(Obj, 'fontSize', pxToVw(info.iconFontSize));
            Reflect.set(Obj, 'color', `${(info.iconColor)}`);
            return Obj;
          case 'list':
            Reflect.set(Obj, 'color', `${(info.defaultFontColor)}`);
            Reflect.set(Obj, 'fontSize', pxToVw(info.defaultFontSize));
            Reflect.set(Obj, 'fontWeight', `${(info.defaultFontWeight)}`);
            return Obj;
          case 'patient':
            Reflect.set(Obj, 'color', `${(info.patientFontColor)}`);
            Reflect.set(Obj, 'fontSize', pxToVw(info.patientFontSize));
            Reflect.set(Obj, 'fontWeight', `${(info.patientFontWeight)}`);
            Reflect.set(Obj, 'backgroundColor', `${(info.patientBackgroundColor)}`);
            return Obj;
          case 'dept':
            Reflect.set(Obj, 'color', `${(info.deptFontColor)}`);
            Reflect.set(Obj, 'fontSize', pxToVw(info.deptFontSize));
            Reflect.set(Obj, 'fontWeight', `${(info.deptFontWeight)}`);
            Reflect.set(Obj, 'backgroundColor', `${(info.deptBackgroundColor)}`);
            return Obj;
        }
      }
    },


  },

  created() {
    this.registerToRefList();
    this.initEventHandler();
    this.handleOnCreated();
  },

  mounted() {
    this.handleOnMounted();
  },

  methods: {
    handleEnd() {
      this.uuid = uuid();
    },

    // 接收父组件传递过来的数据
    executeMethod(key, obj) {
      switch (key) {
        case "callPatientInfo":
          this.uuid = uuid();
          this.$store.dispatch('setCallPatientInfo', obj.msgContent)
          break
      }
    }
  },

  watch: {
    // 获取配置项
    field: {
      handler: function (val) {
        this.uuid = uuid()
        this.optionsInfo = (val.options.callConfig);
      },
      deep: true,
      immediate: true
    },
  },

  destroyed() {
    this.unregisterFromRefList();
  },

};
</script>

<style lang="scss" scoped>
.scene-call-widget {
  background-color: #fff;
  color: #333;
  height: 100px;
  overflow: hidden;
  font-size: 28px;
  padding: 0 28px;
  box-sizing: border-box;
  display: flex;
  justify-content: center;

  .box {
    display: flex;
    align-items: center;

    .left {
      white-space: nowrap;
      padding: 8px 8px;
      color: dodgerblue;
      line-height: normal;
      display: flex;
      align-self: center;
      align-items: center;
      margin-right: 18px;
    }

    .right {
      display: flex;
      flex-direction: row;
      // overflow: hidden;
      // height: 100px;
      flex-basis: calc(100% - 36px - 56px);

      .notice {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;

        &>span {
          margin: 0 15px;
          white-space: nowrap
        }

        .center-font {

          display: flex;
          justify-content: center;
          align-items: center;
          padding: 20px 40px;
          box-sizing: border-box;
        }

        .patient {
          background: #CCDEF0;
          border-radius: 12px;
          opacity: 0.9;

        }

        .dept {
          background: #0059B3;
          border-radius: 12px;
        }
      }
    }
    &.view-mode-2{
      .right {
        .notice {
          &>span {
            margin:0;
          }
          .center-font {
            padding: 20px;
          }
        }
      }
    }
  }
}
</style>
